#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;

int main()
{
    // 读取图像
    cv::Mat srcImage = cv::imread("/Users/chris/Documents/python-learning-team/杨子萱/example_opencv3_cpp/image/test.jpg");
    if (!srcImage.data) return -1;
    cv::imshow("srcImage", srcImage);
    int nRows = srcImage.rows;
    int nCols = srcImage.cols;

    // 定义仿射变换的二位数组点
    // 愿图像和目标对应映射的三个点
    cv::Point2f srcPoint[3];
    cv::Point2f resPoint[3];
    srcPoint[0] = cv::Point2f(0,0);
    srcPoint[1] = cv::Point2f (nCols-1, 0);
    srcPoint[2] = cv::Point2f (0, nRows-1);
    resPoint[0] = cv::Point2f (nCols*0, nRows*0.33);
    resPoint[1] = cv::Point2f (nCols*0.85, nRows*0.25);
    resPoint[2] = cv::Point2f (nCols*0.15, nRows*0.7);

    // 定义仿射变换矩阵
    cv::Mat warpMat(cv::Size(2,3), CV_32F);
    cv::Mat resultImage = cv::Mat::zeros(nRows, nCols, srcImage.type());
    // 计算仿射变换矩阵
    warpMat = cv::getAffineTransform(srcPoint, resPoint);
    // 根据仿射矩阵计算图像仿射变换
    cv::warpAffine(srcImage, resultImage, warpMat, resultImage.size());
    // 设置仿射参数变换
    cv::Point2f centerPoint = cv::Point2f (nCols/2, nRows/2);
    double angle = -50;
    double scale = 0.7;
    // 获取仿射变换矩阵
    warpMat = getRotationMatrix2D(centerPoint, angle , scale);

    // 对原图角度仿射变换
    cv::warpAffine(srcImage, resultImage, warpMat, resultImage.size());
    cv::imshow("resultImage2", resultImage);
    cv::waitKey(0);
    return 0;
}